package com.colorlight.cloud.complete.entity.enumerate;

import com.colorlight.cloud.common.exception.ParameterException;
import com.colorlight.cloud.common.model.ExceptionEnum;
import com.colorlight.cloud.gateway.api.message.constraint.basics.ienum.EnumTrans;
import com.colorlight.iot.proto.complete.entity.CompleteEntity;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

@Getter
public enum InputMode implements EnumTrans<CompleteEntity.InputMode, InputMode> {
    /**
     * 默认未知
     * hdmi-同步信号
     * dvi-异步信号
     * hdmi2.0
     * dp
     */
    DEFAULT(CompleteEntity.InputMode.DEFAULT),
    HDMI(CompleteEntity.InputMode.HDMI,"HDMI"),
    DVI(CompleteEntity.InputMode.DVI,"DVI"),
    HDMI2(CompleteEntity.InputMode.HDMI2,"HDMI2.0"),
    DP(CompleteEntity.InputMode.DP),
    DP1_2(CompleteEntity.InputMode.DP1_2,"DP1.2"),
    HDMI2_1(CompleteEntity.InputMode.HDMI2_1,"HDMI2.1"),
    DVIx4(CompleteEntity.InputMode.DVIx4),
    SDI(CompleteEntity.InputMode.SDI),
    _12G_SDI(CompleteEntity.InputMode._12G_SDI,"12G-SDI"),
    SDIx4(CompleteEntity.InputMode.SDIx4),
    VAG(CompleteEntity.InputMode.VAG),
    CVBS(CompleteEntity.InputMode.CVBS),
    GEN_LOCK(CompleteEntity.InputMode.GEN_LOCK,"GENLOCK"),
    VBO(CompleteEntity.InputMode.VBO),
    LVDS(CompleteEntity.InputMode.LVDS),
    MEDIA(CompleteEntity.InputMode.MEDIA),
    ;

    private final Integer id;
    private final String name;
    private final CompleteEntity.InputMode inputMode;
    private final String displayValue;
    
    InputMode(CompleteEntity.InputMode inputMode, String displayValue) {
        this.id = inputMode.getNumber();
        this.name = inputMode.name();
        this.inputMode = inputMode;
        this.displayValue = displayValue;
    }
    
    InputMode(CompleteEntity.InputMode inputMode) {
        this(inputMode, inputMode.name());
    }

    /**
     * @param inputMode
     * @return 对应的类型
     */
    public static InputMode getInputModeStruct(CompleteEntity.InputMode inputMode) {
        Objects.requireNonNull(inputMode, "inputMode can not be null.");
        return Arrays.stream(InputMode.values())
                .filter(e -> e.name.equals(inputMode.name()))
                .findFirst()
                .orElseThrow(() -> new ParameterException(ExceptionEnum.NOT_EXIST_ENUM));
    }

    @Override
    public CompleteEntity.InputMode toProto() {
        return this.inputMode;
    }

    @Override
    public InputMode formProto(CompleteEntity.InputMode inputMode) {
        return getInputModeStruct(inputMode);
    }
}

